//
//  MineSettingViewController.m
//  Btpin
//
//  Created by Vic on 2019/3/28.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "MineSettingViewController.h"
#import "LYSettingCell.h"

#import "LYSettingchangeMobileController.h"
#import "LYSettingUsernameController.h"
#import "LYSettingChanagePasswordController.h"

@interface MineSettingViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableview;
@property (nonatomic, strong) NSArray *dataArray;
@end

@implementation MineSettingViewController

-(NSArray *)dataArray{
    if (!_dataArray) {
        _dataArray = @[
                       @{@"name":@"修改手机号",@"detail":@"13655288776"},
                       @{@"name":@"设置用户名",@"detail":@"wangxiaofei"},
                       @{@"name":@"修改密码",@"detail":@""}];
    }
    return _dataArray;
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
}
- (void)initUI {
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-HeightOfStatusBarAndNavigationBar) style:UITableViewStyleGrouped];
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    self.tableview.showsVerticalScrollIndicator = NO;
    self.tableview.estimatedRowHeight = 0;
    self.tableview.estimatedSectionHeaderHeight = 0;
    self.tableview.estimatedSectionFooterHeight = 0;
    self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableview.backgroundColor = RGB(247, 247, 247);
    self.tableview.sectionIndexBackgroundColor = [UIColor clearColor];
    
    [self.tableview registerClass:[LYSettingCell class] forCellReuseIdentifier:kCellIdentifier_LYSettingCell];
    [self.view addSubview:self.tableview];
    
    UIButton *footBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    footBtn.frame = CGRectMake( 0, 0, 80, 45);
    footBtn.backgroundColor = [UIColor whiteColor];
    [footBtn setTitle:@"退出当前账户" forState:UIControlStateNormal];
    [footBtn setTitleColor:THEMECOLOR_OF_RED forState:UIControlStateNormal];
    footBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [footBtn addTarget:self action:@selector(footBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    self.tableview.tableFooterView = footBtn;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LYSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_LYSettingCell forIndexPath:indexPath];
    NSDictionary *dic = self.dataArray[indexPath.row];
    if (indexPath.row == 0) {
         [cell setTitle:dic[@"name"] detail:UD_GetOForK(isMobile)];
    }else if (indexPath.row == 1){
         [cell setTitle:dic[@"name"] detail:UD_GetOForK(isUserName)];
    }else{
        [cell setTitle:dic[@"name"] detail:@""];
    }
    return cell;
}

#pragma mark -- UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        LYSettingchangeMobileController *mobileVC = [[LYSettingchangeMobileController alloc] init];
        mobileVC.mobile = UD_GetOForK(isMobile);
        [self.navigationController pushViewController:mobileVC animated:YES];
    } else if (indexPath.row == 1) {
        LYSettingUsernameController *userVC = [[LYSettingUsernameController alloc] init];
        __weak __typeof(self)weakSelf = self;
        userVC.block = ^{
            //用户名修改回调
            [weakSelf.tableview reloadData];
        };
        [self.navigationController pushViewController:userVC animated:YES];
    } else {
        LYSettingChanagePasswordController *passwordVC = [[LYSettingChanagePasswordController alloc] init];
        passwordVC.isExistPWD = NO;
        [self.navigationController pushViewController:passwordVC animated:YES];
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.00001;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 8.0f;
}
#pragma mark -- Action
- (void)footBtnClick:(UIButton *)button{
    
}

@end
